package cn.bdqn.pn.service.user.impl;

import cn.bdqn.pn.pojo.user.Resource;
import cn.bdqn.pn.reposity.user.ResourceReposity;
import cn.bdqn.pn.service.user.ResourceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

import java.util.List;

@Service("resourceService")
public class ResourceServiceImpl implements ResourceService {
    @Autowired
    private ResourceReposity resourceReposity;

    @Override
    public Page<Resource> selectResource(Integer pageNo, Integer pageSize) {
        Pageable pageable=new PageRequest(pageNo,pageSize);

        Page<Resource> page = resourceReposity.findAll(pageable);
        return page;
    }

    @Override
    public void addResource(Resource resource) {
        resourceReposity.save(resource);
    }

    @Override
    public void updateResource(Resource resource) {
        resourceReposity.save(resource);
    }

    @Override
    public void deleteResource(Integer resourceid) {
        resourceReposity.delete(resourceid);
    }

    @Override
    public Resource findResourceById(Integer resourceid) {
        return resourceReposity.findOne(resourceid);
    }

    @Override
    public List<Resource> selectAll() {
        return resourceReposity.findAll();
    }
}
